package sg.edu.nus.iss.team8s.vmcs.PropertyLoader;
/**
 * 
 * @author Nie XiaoYi
 *
 */

import sg.edu.nus.iss.team8s.vmcs.beans.Coin;
import sg.edu.nus.iss.team8s.vmcs.beans.DrinksBrand;
import sg.edu.nus.iss.team8s.vmcs.beans.DrinksStoreItem;
import sg.edu.nus.iss.team8s.vmcs.beans.StoreItem;

public class DrinkPropertyLoader extends FilePropertyLoader {
	
	private final String PRICEKEY = "Price";
	private static DrinkPropertyLoader instance = null;
	
	private DrinkPropertyLoader(String fileName) {
		super(fileName);
		// TODO Auto-generated constructor stub
	}
	
	public static synchronized DrinkPropertyLoader getInstance(String fileName){
		if(instance == null){
			instance = new DrinkPropertyLoader(fileName);
		}
		return instance;
	}
	
	public StoreItem getItem(int identifier){
		String name = getValue(this.NAMEKEY+String.valueOf(identifier));
		String price = getValue(this.PRICEKEY+String.valueOf(identifier));
		String quantity = getValue(this.QUANTITYKEY+String.valueOf(identifier));
		DrinksBrand drink = new DrinksBrand(name,Integer.parseInt(price));
		StoreItem item = new DrinksStoreItem(Integer.parseInt(quantity),drink);
		return item;
	}
	
	public void setItem(int identifier, StoreItem drinkItem){
		DrinksBrand drinksBrand = (DrinksBrand)drinkItem.getContent();
		setValue(this.NAMEKEY+String.valueOf(identifier),drinksBrand.getName());
		setValue(this.PRICEKEY+String.valueOf(identifier),String.valueOf(drinksBrand.getPrice()));
		setValue(this.QUANTITYKEY+String.valueOf(identifier),String.valueOf(drinkItem.getQuantity()));
	}
}
